1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4 using
UnityEngine.UI;
5 using
UnityEngine.SceneManagement;
6
7 public
class GameManager : MonoBehaviour {
8
9     
public static GameManager instance;
10
11     
public GameObject pausePanel, gameOverPanel;
12
13     
[SerializeField]
14     
public Text scoreText, bestScoreText, GObestScoreText, newHighScoreText;
15
16     
[SerializeField]
17     
public Button tapToStart, pauseButton;
18
19     
[SerializeField]
20     
private Button musicBtn;
21
22     
[SerializeField]
23     
private Sprite[] musicIcons;
24
25     
void Start () {
26         Time.timeScale =
0f;
27         pauseButton.gameObject.SetActive(
false);
28         MakeInstance();
29         CheckToPlayMusic();
30     }
31     
32     
void MakeInstance () {
33         
if (instance == null) {
34             instance =
this;
35         }
36     }
37
38     
void CheckToPlayMusic() {
39         
if (Game.GetMusicState() == 1)
40         {
41             MusicController.instance.PlayMusic(
true);
42             musicBtn.image.sprite = musicIcons[
1];
43         }
else {
44             MusicController.instance.PlayMusic(
false);
45             musicBtn.image.sprite = musicIcons[
0];
46         }
47     }
48
49     
public void TapToStart() {
50         Time.timeScale =
1f;
51         tapToStart.gameObject.SetActive(
false);
52         pauseButton.gameObject.SetActive(
true);
53     }
54
55     
public void PauseGame() {
56         Time.timeScale =
0f;
57         pausePanel.SetActive(
true);
58         bestScoreText.text =
"Best Score : " + Score.instance.GetHighScore();
59     }
60
61     
public void ResumeGame() {
62         Time.timeScale =
1f;
63         pausePanel.SetActive(
false);
64     }
65
66     
public void RestartGame() {
67         SceneManager.LoadScene(
"Gameplay");
68     }
69
70     
public void MainMenu() {
71         SceneManager.LoadScene(
"MainMenu");
72     }
73
74     
public void GameOver() {
75         gameOverPanel.SetActive(
true);
76         GObestScoreText.text =
"Best Score : " + Score.instance.GetHighScore();
77     }
78
79     
public void IfPlayerDied(int diedScore) {
80         bestScoreText.text =
"Best Score : " + ScoreCount.instance.countScore;
81
82         
if (diedScore > Score.instance.GetHighScore()) {
83             Score.instance.SetHighScore(diedScore);
84             newHighScoreText.gameObject.SetActive(
true);
85         }
86
87         bestScoreText.text =
"Best Score : " + Score.instance.GetHighScore();
88     }
89
90     
public void MusicButton()
91     {
92         
if (Game.GetMusicState() == 0)
93         {
94             Game.SetMusicState(
1);
95             MusicController.instance.PlayMusic(
true);
96             musicBtn.image.sprite = musicIcons[
1];
97         }
98         
else if (Game.GetMusicState() == 1)
99         {
100             Game.SetMusicState(
0);
101             MusicController.instance.PlayMusic(
false);
102             musicBtn.image.sprite = musicIcons[
0];
103         }
104     }
105 }



Trò chơi Halloween vui nhộn trong UNITY Engine 10.800 lượt xem

Gõ tìm kiếm nhanh...